import type { Slots } from "vue";

/**
 * 获取插槽VNode
 * @param slots 插槽对象
 * @param props 属性对象
 * @param prop 属性键名
 * @returns [] / null / undefained
 */
export function getSlotVNode<T>(
  slots: Slots,
  props: Record<string, any>,
  prop = "default"
): T | null | undefined {
  if (props[prop] === false || props[prop] === null) {
    return null;
  }

  const s: T = props[prop] || slots[prop];
  if (typeof s === "function") {
    return s();
  }
  return s;
}
